package com.spring.sunflower.conversation;

import com.spring.sunflower.base.BaseObserver;
import com.spring.sunflower.base.BasePresenter;
import com.spring.sunflower.bean.AnchorDetailBean;
import com.spring.sunflower.bean.ChatGiftBean;
import com.spring.sunflower.bean.CommonBean;
import com.spring.sunflower.bean.GiveGiftBean;
import com.spring.sunflower.bean.LiveAcceptChatBean;
import com.spring.sunflower.constant.Constant;

import java.util.Map;

import io.reactivex.rxjava3.core.Observable;

/**
 * Created by Kevin on 2021/7/15<br/>
 * <p>
 * Describe:<br/>
 */
public class ChatVideoPresenter extends BasePresenter<ChatVideoView> {
    public ChatVideoPresenter(ChatVideoView baseView) {
        super(baseView);
    }

    public void loadAllGift() {
        Observable<ChatGiftBean> observable = requestDataSource.getAllGift();
        addDisposable(observable, new BaseObserver<ChatGiftBean>() {
            @Override
            public void onSuccess(ChatGiftBean bean) {
                baseView.showGiftList(bean.getDatas());

            }

            @Override
            public void onError(int status, String msg) {

            }
        });
    }

    public void getDetail(String userId) {
        Observable<AnchorDetailBean> observable = requestDataSource.requestAnchorDetail(userId);
        addDisposable(observable, new BaseObserver<AnchorDetailBean>() {
            @Override
            public void onSuccess(AnchorDetailBean bean) {
                baseView.showAnchorData(bean.getDatas());

            }

            @Override
            public void onError(int status, String msg) {

            }
        });
    }

    public void sendGift(Map<String, String> map,int pos) {
        Observable<GiveGiftBean> observable = requestDataSource.sendGift(map);
        addDisposable(observable, new BaseObserver<GiveGiftBean>() {
            @Override
            public void onSuccess(GiveGiftBean bean) {
                baseView.sendGiftSuccess(bean.getDatas().getData(),pos);

            }

            @Override
            public void onError(int status, String msg) {
                baseView.sendGiftFailed("ErrCode=" + status + "::msg=" + msg);
            }
        });
    }

    public void accept(String userId, String anchorId) {
        String gender = getField(Constant.KEY_GENDER, "");
        Observable<LiveAcceptChatBean> observable;
        if ("1".equals(gender)) {
            observable = requestDataSource.liveAcceptChatMember(anchorId);
        } else {
            observable = requestDataSource.liveAcceptChat(userId, anchorId);
        }
        addDisposable(observable, new BaseObserver<LiveAcceptChatBean>(baseView) {

            @Override
            public void onSuccess(LiveAcceptChatBean bean) {
                baseView.acceptSuccess(bean.getDatas().getData());
            }

            @Override
            public void onError(int status, String msg) {

            }
        });
    }

    public void refuse(String userId, String anchorId) {
        String gender = getField(Constant.KEY_GENDER, "");
        Observable<CommonBean> observable;
        if ("1".equals(gender)) {
            observable = requestDataSource.liveRefuseChatMember(anchorId);
        } else {
            observable = requestDataSource.liveRefuseChatAnchor(userId, anchorId);
        }
        addDisposable(observable, new BaseObserver<CommonBean>() {

            @Override
            public void onSuccess(CommonBean bean) {
                baseView.refuseSuccess();
            }

            @Override
            public void onError(int status, String msg) {

            }
        });
    }

    public void cancel(String userId, String anchorId) {
        String gender = getField(Constant.KEY_GENDER, "");
        Observable<CommonBean> observable;
        if ("1".equals(gender)) {
            observable = requestDataSource.liveCancelDialingMember(userId, anchorId);
        } else {
            observable = requestDataSource.liveCancelDialing(anchorId);
        }
        addDisposable(observable, new BaseObserver<CommonBean>() {

            @Override
            public void onSuccess(CommonBean bean) {
                baseView.cancelSuccess();
            }

            @Override
            public void onError(int status, String msg) {

            }
        });
    }

    public void callShowHangup(String roomId) {
        Observable<CommonBean> observable = requestDataSource.liveCallShow(roomId);
        addDisposable(observable, new BaseObserver<CommonBean>(baseView) {

            @Override
            public void onSuccess(CommonBean bean) {
                baseView.cancelSuccess();
            }

            @Override
            public void onError(int status, String msg) {

            }
        });
    }

    public void hangup(String roomId) {
        String gender = getField(Constant.KEY_GENDER, "");
        Observable<CommonBean> observable;
        if ("1".equals(gender)) {
            observable = requestDataSource.liveStopChatMember(roomId);
        } else {
            observable = requestDataSource.liveStopChatAnchor(roomId);
        }
        addDisposable(observable, new BaseObserver<CommonBean>(baseView) {

            @Override
            public void onSuccess(CommonBean bean) {
                baseView.hangupSuccess();
            }

            @Override
            public void onError(int status, String msg) {

            }
        });
    }

    public void onlineVerify(String roomId) {
        String gender = getField(Constant.KEY_GENDER, "");
        Observable<CommonBean> observable;
        if ("1".equals(gender)) {
            observable = requestDataSource.liveOnlineVerifyMember(roomId);
        } else {
            observable = requestDataSource.liveOnlineVerifyAnchor(roomId);
        }
        addDisposable(observable, new BaseObserver<CommonBean>() {

            @Override
            public void onSuccess(CommonBean bean) {
            }

            @Override
            public void onError(int status, String msg) {

            }
        });
    }

}
